package com.sprinboot_vue.blog_springboot.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Thomas
 * @version 1.0
 * @date 2021/11/20 20:54
 */
@Configuration
@CrossOrigin
/**
 * 由于是两个端口进行访问，已经跨域了。
 * 所以需要配置跨域请求！！！
 */
//跨域请求配置
public class CrosConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET","POST","HEAD","PUT","DELETE","OPTIONS")
                .allowCredentials(false)
                .maxAge(3600)
                .allowedHeaders("*");
    }
}
